﻿using System;
using System.Windows.Forms;

namespace MoneyWentWhere.WinFormsUI.UI
{
    public class CustomColumn<EditT, ValueT> : DataGridViewColumn
        where EditT : Control, IDataGridViewEditingControl
    {
        public CustomColumn()
            : base(new CustomCell<EditT, ValueT>())
        {
        }

        public override DataGridViewCell CellTemplate
        {
            get
            {
                return base.CellTemplate;
            }
            set
            {
                // Ensure that the cell used for the template is a CustomCell.
                if (value != null &&
                    !value.GetType().IsAssignableFrom(typeof(CustomCell<EditT, ValueT>)))
                {
                    throw new InvalidCastException("Must be an CustomCell");
                }
                base.CellTemplate = value;
            }
        }
    }
}
